package com.ruoyi.web.controller.myController;


import com.ruoyi.system.domain.Myuser;
import com.ruoyi.system.domain.vo.LoginVO;
import com.ruoyi.system.domain.vo.Results;
import com.ruoyi.system.service.IMyuserService;
import com.ruoyi.system.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogoutController {
    @Autowired
    private IMyuserService myuserService;
    @Autowired
    private RedisService redisService;

    @PostMapping("/api/logout")
    public Results logout(@RequestBody LoginVO loginVO){
        Myuser user = myuserService.selectMyuserByUserid(loginVO.getId().longValue());
        if(user==null){
            return new Results(500,"","");
        }
        user.setStatus(0L);
        myuserService.updateMyuser(user);
        Integer loginCount =(Integer) redisService.get("LoginCount");
        redisService.decr("LoginCount",1);
        return new Results(200,"用户已下线","");
    }
}
